<template>
  <div class="user-panel">
    <img
      class="avatar"
      :src="avatarImg"
      @click="handleAvatar"
    />
    <span
      class="name"
      @click="handleUser"
    >{{name}}</span>
  </div>
</template>

<script>
import notLogin from '@/assets/icons/not-login.png'
import defAvatar from '@/assets/icons/def-avatar.png'

export default {
  name: 'user-panel',
  computed: {
    avatarImg() {
      return this.isLogin ? this.avatar || defAvatar : notLogin
    },
    name() {
      return this.isLogin ? this.nickname : '戳我登陆'
    }
  },
  props: {
    isLogin: Boolean,
    avatar: String,
    nickname: String,
    handleAvatar: Function,
    handleUser: Function
  }
}
</script>

<style lang="stylus">
$size = 60px;

.user-panel {
  display: flex;
  align-items: center;
  margin: 0 16px;
  padding: 16px 0;
  border-bottom: 1px solid $app-bgc;

  >.avatar {
    width: $size;
    height: $size;
    border-radius: 50%;
    overflow: hidden;
  }

  >.name {
    flex: 1;
    margin-left: 20px;
    font-size: 20px;
  }
}
</style>
